package cn.test.learnkotlin.v1

class CConditionControl {

    val a = 1;
    val b = 2;

    private fun fooIf() {
        var max1 = a
        if (a < b) {
            max1 = b
        }
        var max2: Int
        if (a > b) {
            max2 = a
        } else {
            max2 = b
        }
        val max3 = if (a > b) a else b
        val max = if (a > b) {
            println("choose a")
            a
        } else {
            println("choose b")
            b
        }
    }

    private fun fooWhen() {
        var x = 1
        when (x) {
            1 -> print("x==1")
            2 -> print("x==2")
            else -> print("x!=1 && x!=2")
        }
        when (x) {
            0, 1 -> print("x==0 || x==1")
            in 1..10 -> print("in range 1..10")
            !in 10..20 -> print("not in 10..20")
            else -> print("otherwise")
        }
    }

    private fun hasPrefix(s: Any) = when (s) {
        is String -> s.startsWith("prefix")
        else -> false
    }

    private fun fooWhen1() {
        val items = arrayOf("apple", "banana", "kiwi")
        when {
            "orange" in items -> print("juicy")
            "apple" in items -> print("apple is fine too")
        }
    }

    fun main() {
        fooWhen1()
    }
}

fun main() {
    CConditionControl().main()
}